package com.panwenliang2008.eatwhat.data

import com.panwenliang2008.eatwhat.data.dao.FoodDao
import com.panwenliang2008.eatwhat.data.entity.Food

class FoodRepository constructor(
    private val foodDao: FoodDao
) {
    fun getAll() = foodDao.getAll()
    fun getRandomFood(foodInt: Int) = foodDao.getRandomFood(foodInt)
    suspend fun delete(food: Food) = foodDao.delete(food)
    suspend fun insert(food: Food) = foodDao.insert(food)

    companion object {

        // For Singleton instantiation
        @Volatile private var instance: FoodRepository? = null

        fun getInstance(foodDao: FoodDao) =
            instance ?: synchronized(this) {
                instance ?: FoodRepository(foodDao).also { instance = it }
            }
    }
}